﻿using System;
using System.Collections.Generic;
using System.Text;
using CPF;
using CPF.Charts;
using CPF.Drawing;

namespace CPFManager
{
    class MainModel : CPF.CpfObject
    {
        public MainModel()
        {
            Random random = new Random();
            销量 = new Collection<IChartData>();
            for (int j = 0; j < 3; j++)
            {
                var chartData = new ChartLineData
                {
                    LineFill = Color.FromRgb((byte)random.Next(0, 256), (byte)random.Next(0, 256), (byte)random.Next(0, 256)),
                    Name = "产品" + j,
                };
                销量.Add(chartData);
                for (int i = 0; i < 10; i++)
                {
                    chartData.Data.Add(random.Next(100));
                }
            }

            利润 = new Collection<IChartData>();
            for (int j = 0; j < 3; j++)
            {
                var chartData = new ChartBarData
                {
                    Fill = Color.FromRgb((byte)random.Next(0, 256), (byte)random.Next(0, 256), (byte)random.Next(0, 256)),
                    Name = "产品" + j,
                };
                利润.Add(chartData);
                for (int i = 0; i < 10; i++)
                {
                    chartData.Data.Add(random.Next(1000));
                }
            }

            销量比例 = new Collection<PieChartData>();
            for (int j = 0; j < 3; j++)
            {
                var chartData = new PieChartData
                {
                    Fill = Color.FromRgb((byte)random.Next(0, 256), (byte)random.Next(0, 256), (byte)random.Next(0, 256)),
                    Name = "产品" + j,
                    Value = random.Next(10000),
                };
                销量比例.Add(chartData);
            }
            利润比例 = new Collection<PieChartData>();
            for (int j = 0; j < 3; j++)
            {
                var chartData = new PieChartData
                {
                    Fill = Color.FromRgb((byte)random.Next(0, 256), (byte)random.Next(0, 256), (byte)random.Next(0, 256)),
                    Name = "产品" + j,
                    Value = random.Next(10000),
                };
                利润比例.Add(chartData);
            }


            表格数据 = new Collection<(string, Image, string)>();
            for (int i = 0; i < 100; i++)
            {
                表格数据.Add((i.ToString(), "res://CPFManager/icon.png", "dgsda" + i));
            }

            Nodes = new Collection<Node>();
            for (int i = 0; i < 30; i++)
            {
                Node node = new Node { Text = "node" + i };
                for (int j = 0; j < 10; j++)
                {
                    node.Nodes.Add(new Node { Text = "子节点" + j });
                }
                Nodes.Add(node);
            }
        }

        public string UserName
        {
            get { return GetValue<string>(); }
            set { SetValue(value); }
        }
        public string Password
        {
            get { return GetValue<string>(); }
            set { SetValue(value); }
        }
        public bool RememberPassword
        {
            get { return GetValue<bool>(); }
            set { SetValue(value); }
        }
        public bool AutoLogin
        {
            get { return GetValue<bool>(); }
            set { SetValue(value); }
        }

        public void Login(LoginWindow loginWindow)
        {
            //if (string.IsNullOrWhiteSpace(UserName))
            //{
            //    CPF.Controls.MessageBox.Show("用户名不能为空！");
            //    return;
            //}
            //if (string.IsNullOrWhiteSpace(Password))
            //{
            //    CPF.Controls.MessageBox.Show("密码不能为空！");
            //    return;
            //}
            loginWindow.Visibility = CPF.Visibility.Collapsed;
            new Window1 { DataContext = this, CommandContext = this }.Show();
        }

        public Collection<IChartData> 销量
        {
            get { return GetValue<Collection<IChartData>>(); }
            set { SetValue(value); }
        }

        public Collection<IChartData> 利润
        {
            get { return GetValue<Collection<IChartData>>(); }
            set { SetValue(value); }
        }

        public Collection<PieChartData> 销量比例
        {
            get { return GetValue<Collection<PieChartData>>(); }
            set { SetValue(value); }
        }
        public Collection<PieChartData> 利润比例
        {
            get { return GetValue<Collection<PieChartData>>(); }
            set { SetValue(value); }
        }
        public Collection<(string, Image, string)> 表格数据
        {
            get { return GetValue<Collection<(string, Image, string)>>(); }
            set { SetValue(value); }
        }

        public Collection<Node> Nodes
        {
            get { return GetValue<Collection<Node>>(); }
            set { SetValue(value); }
        }

        public Image Screenshot
        {
            get { return GetValue<Image>(); }
            set { SetValue(value); }
        }

        public void ScreenCapture(Window1 window)
        {
            Screenshot = window.Screen.Screenshot();
        }
    }

    public class Node
    {
        public string Text { get; set; }

        public Collection<Node> Nodes { get; set; } = new Collection<Node>();
    }
}
